$OpenBSD: patch-clients_lcdproc_machine_OpenBSD_c,v 1.3 2014/09/17 14:52:18 espie Exp $

The code distributed with LCDproc for querying the process table is out of date.

--- clients/lcdproc/machine_OpenBSD.c.orig	Mon Dec 27 06:32:56 2010
+++ clients/lcdproc/machine_OpenBSD.c	Wed Sep 17 08:49:43 2014
@@ -44,13 +44,14 @@
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/sysctl.h>
-#include <sys/dkstat.h>
+#include <sys/sched.h>
 #include <sys/ucred.h>
 #include <sys/mount.h>
 #include <sys/time.h>
 #include <sys/user.h>
-/* take care if $ARCH != i386! */
-#include <i386/apmvar.h>
+#ifdef WITH_APM
+#include <machine/apmvar.h>
+#endif
 #include <kvm.h>
 #include <errno.h>
 
@@ -61,7 +62,7 @@
 
 static int pageshift;
 #define pagetok(size) ((size) << pageshift)
-#define PROCSIZE(pp) ((pp).vm_tsize + (pp).vm_dsize + (pp).vm_ssize)
+#define PROCSIZE(pp) ((pp)->p_vm_tsize + (pp)->p_vm_dsize + (pp)->p_vm_ssize)
 
 
 int machine_init(void)
@@ -88,6 +89,7 @@ int machine_close(void)
 
 int machine_get_battstat(int *acstat, int *battflag, int *percent)
 {
+#ifdef WITH_APM
 	int apmd;
 	struct apm_power_info api;
 
@@ -145,6 +147,11 @@ int machine_get_battstat(int *acstat, int *battflag, i
 	*percent = api.battery_life;
 
 	close(apmd);
+#else
+	*acstat   = LCDP_AC_ON;
+	*battflag = LCDP_BATT_ABSENT;
+	*percent  = 100;
+#endif
 
 	return(TRUE);
 }
@@ -294,7 +301,7 @@ int machine_get_procs(LinkedList *procs)
 		return(FALSE);
 	}
 
-	kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &nproc);
+	kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &nproc);
 	if (kprocs == NULL)
 	{
 		perror("kvm_getprocs");
@@ -311,10 +318,10 @@ int machine_get_procs(LinkedList *procs)
 			kvm_close(kvmd);
 			return(FALSE);
 		}
-		strncpy(p->name, kprocs->kp_proc.p_comm, 15);
+		strncpy(p->name, kprocs->p_comm, 15);
 		p->name[15] = '\0';
-		p->totl = pagetok(PROCSIZE(kprocs->kp_eproc.e_vm));
-		p->number = kprocs->kp_proc.p_pid;
+		p->totl = pagetok(PROCSIZE(kprocs));
+		p->number = kprocs->p_pid;
 		LL_Push(procs, (void *)p);
 
 		kprocs++;
